﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using System.IO;
namespace Congducsan
{
    public partial class FrmTuychon : Form
    {
        
        public FrmTuychon()
        {
            InitializeComponent();
        }
      
        private void FrmTuychon_FormClosing(object sender, FormClosingEventArgs e)
        {
         //   DradApplication.DradApp.FormMain.Show();
        }

        private void FrmTuychon_Resize(object sender, EventArgs e)
        {
            this.Size = new Size(547, 518);
        }

        private void CANCEL_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FrmTuychon_Load(object sender, EventArgs e)
        {
            loadSettingReg();
        }

        private void LOAD_Click(object sender, EventArgs e)
        {
            OpenFileDialog openDialog = new OpenFileDialog();
            openDialog.Filter = "Data files (*.mdb)|*.mdb";
            openDialog.InitialDirectory = Directory.GetCurrentDirectory();
            openDialog.Multiselect = false;
            openDialog.RestoreDirectory = true;
            string file = "";
            if (openDialog.ShowDialog() == DialogResult.OK)
            {
                file = openDialog.FileName;
                MessageBox.Show("Bạn đã chọn " + file, "Thông báo");
            }
        }
        //Lưu settings vào registry
        private void saveSettingReg()
        {
            RegistryKey regKey = Registry.CurrentUser;
            regKey = regKey.CreateSubKey("Software\\HaithanhSoft\\Drad2012\\Congducsan");
            string Values = "";
            //Ti le
            Values = TxtTle.Text; //0
            Values = Values +"\t"+ TxtTleT.Checked.ToString(); //1
            Values = Values +"\t"+ TxtBhatch.Text; //2
            Values = Values +"\t"+ TxtGkt.Checked.ToString(); //3
            Values = Values +"\t"+ txtTyleCdien.Text; //4
            regKey.SetValue("GlobalTile",Values);
            string Values1;
            string[] Var1 = regKey.GetValue("Vatlieu").ToString().Split('\t');
            Values1 = txtVlTd.Text;//0
            Values1 = Values1 +"\t"+ txtVlTc.Text;//1
            Values1 = Values1 +"\t"+ txtVlGiaco.Text;//2
            Values1 = Values1 +"\t"+ txtVlTn.Text;//3
            Values1 = Values1+"\t"+ txtVlHt.Text;//4
            Values1 = Values1 +"\t"+ txtVlHg.Text;//5
            Values1 = Values1 +"\t"+ txtVlm.Text;//6
            Values1 = Values1 +"\t"+ txtVlBc.Text;//7
            Values1 = Values1 +"\t"+ txtVlThan.Text;//8
            Values1 = Values1 +"\t"+ Var1[9];//9
            Values1 = Values1 +"\t"+ txtVlDem.Text;//10
            regKey.SetValue("Vatlieu", Values1);

            string Values2;
            string[] Var2 = regKey.GetValue("KtDatyeu").ToString().Split('\t');
            Values2 = txtXuly .Checked.ToString();//0
            Values2 = Values2 +"\t"+ txtGiaip1.Checked.ToString();//1
            Values2 = Values2 +"\t"+ txtLopcat .Text;//2
            Values2 = Values2 +"\t"+ txtGiaip2.Checked.ToString();//3
            Values2 = Values2 + "\t" + Var2[4];
            Values2 = Values2 + "\t" + Var2[5];
            Values2 = Values2 + "\t" + Var2[6];
            Values2 = Values2 + "\t" + Var2[7];
            Values2 = Values2 + "\t" + Var2[8];
            regKey.SetValue("KtDatyeu", Values2);

            string Values3;
            //Tuy chon ve cac mat chieu
            Values3 = optFullPlan.Checked.ToString();
            Values3 = Values3 +"\t"+ optDemiPlan.Checked.ToString();
            Values3 = Values3 +"\t"+ optFullSide.Checked.ToString();
            Values3 = Values3 +"\t"+ optDemiSide.Checked.ToString();
            regKey.SetValue("Matchieu", Values3);
            regKey.Close();
           
        }
              //Load settings từ registry vào form
        private void loadSettingReg()
        {
            RegistryKey regKey = Registry.CurrentUser;
            RegistryKey testKey = regKey.OpenSubKey("Software\\HaithanhSoft\\Drad2012\\Congducsan");
            if (testKey != null)
            {
                regKey = regKey.CreateSubKey("Software\\HaithanhSoft\\Drad2012\\Congducsan");
                string str = regKey.GetValue("GlobalTile").ToString();
                string[] STR = str.Split('\t');
                int i = 0;
                //Ti le
                TxtTle.Text=STR[i++]; //0
                TxtTleT.Checked=bool.Parse(STR[i++]); //1
                TxtBhatch.Text=STR[i++]; //2
                TxtGkt.Checked = bool.Parse(STR[i++]); //3
                txtTyleCdien.Text=STR[i++]; //4

                string str1 = regKey.GetValue("Vatlieu").ToString();
                string[] STR1 = str1.Split('\t');
                i = 0;
                txtVlTd.Text=STR1[i++];//0
                txtVlTc.Text = STR1[i++];//1
                txtVlGiaco.Text = STR1[i++];//2
                txtVlTn.Text = STR1[i++];//3
                txtVlHt.Text = STR1[i++];//4
                txtVlHg.Text = STR1[i++];//5
                txtVlm.Text = STR1[i++];//6
                txtVlBc.Text = STR1[i++];//7
                txtVlThan.Text = STR1[i++];//8
                //Var1[9];//9
                i++;
                txtVlDem.Text = STR1[i++];//10

                string str2 = regKey.GetValue("KtDatyeu").ToString();
                string[] STR2 = str2.Split('\t');
                i = 0;
                txtXuly.Checked=bool.Parse(STR2[i++]);//0
                txtGiaip1.Checked=bool.Parse(STR2[i++]);//1
                txtLopcat.Text = STR2[i++];//2
                txtGiaip2.Checked = bool.Parse(STR2[i++]);//3

                string str3 = regKey.GetValue("Matchieu").ToString();
                string[] STR3 = str3.Split('\t');
                i = 0;
                optFullPlan.Checked = bool.Parse(STR3[i++]);
                optDemiPlan.Checked = bool.Parse(STR3[i++]);
                optFullSide.Checked = bool.Parse(STR3[i++]);
                optDemiSide.Checked = bool.Parse(STR3[i++]);
                regKey.Close();
            }
        }

        private void FrmTuychon_FormClosed(object sender, FormClosedEventArgs e)
        {
            saveSettingReg();
        }

   
    }
}
